package com.ztools.pc.service.impl.information;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ztools.common.model.pc.information.InformationSignIn;
import com.ztools.common.util.common.PageUtil;
import com.ztools.pc.mapper.information.InformationSignInMapper;
import com.ztools.pc.service.information.InformationSignInService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author seeTools
 * @since 2023-05-31
 */
@Service
public class InformationSignInServiceImpl extends ServiceImpl<InformationSignInMapper, InformationSignIn> implements InformationSignInService {

    @Resource
    private InformationSignInMapper informationSignInMapper;

    /**
     * 分页查询
     *
     * @param pageUtil 分页数据
     * @return 对象
     */
    @Override
    public Page<InformationSignIn> findList(PageUtil<InformationSignIn> pageUtil) {
        List<OrderItem> orders = new ArrayList<>();
        QueryWrapper<InformationSignIn> queryWrapper = getQueryWrapper(pageUtil.getParams());
        Page<InformationSignIn> pages = new Page<>(pageUtil.getPage(), pageUtil.getSize());
        // 排序数据  StrUtil.toUnderlineCase huTools将驼峰装换为下划线格式
        orders.add(new OrderItem(StrUtil.toUnderlineCase(pageUtil.getSortName()), "asc".equals(pageUtil.getSortOrder())));
        pages.setOrders(orders);
        Page<InformationSignIn> page = page(pages, queryWrapper);
        dictionary(page.getRecords());
        return page;
    }

    @Override
    public List<InformationSignIn> findByObject(InformationSignIn informationSignIn) {
        QueryWrapper<InformationSignIn> queryWrapper = new QueryWrapper<>(informationSignIn);
        return list(queryWrapper);
    }

    @Override
    public boolean update(InformationSignIn informationSignIn) {
        boolean b = false;
        // 修改前先获取，在删除（乐观锁）
        InformationSignIn byId = getById(informationSignIn);
        b = updateById(informationSignIn);
        return b;
    }

    @Override
    public boolean delete(InformationSignIn informationSignIn) {
        boolean b = false;
        InformationSignIn byId = getById(informationSignIn);
        b = removeById(informationSignIn);
        return b;
    }


    @Override
    public boolean checkSing(Long memberId) {
        InformationSignIn informationSignIn = informationSignInMapper.checkSing(memberId);
        return informationSignIn != null;
    }

    public QueryWrapper<InformationSignIn> getQueryWrapper(InformationSignIn informationSignIn) {
        QueryWrapper<InformationSignIn> queryWrapper = new QueryWrapper<>();
        return queryWrapper;
    }

    /**
     * 字典翻译
     *
     * @param informationSignInList 对象集合
     */
    public void dictionary(List<InformationSignIn> informationSignInList) {
        for (InformationSignIn informationSignIn : informationSignInList) {
            dictionary(informationSignIn);
        }
    }

    public void dictionary(InformationSignIn informationSignIn) {
        if (informationSignIn != null) {
        }
    }

}

